package define.Demo_02.Phone;

public class PhoneTest {
    public static void main(String[] args) {
        //创建对象
        Phone p1 = new Phone("huawei", 3999.0, "black");
        Phone p2 = new Phone("xiaomi", 2999.0, "white");
        Phone p3 = new Phone("apple", 9999.0, "gold");
        //创建数组
        Phone[] arr = new Phone[3];
        //将对象放入数组
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;
        //遍历数组
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            Phone phone = arr[i];
            sum += phone.getPrice();
        }
        System.out.println("平均价格为："+sum/arr.length);
    }
}
